﻿#if DESKTOP_TARGET

using System;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace gamecontrol
{
    public class InputKeyboard : InputBase
    {
        private int repeatMult = 1;
        private Key prevKeyVal;

        public InputKeyboard(FrameworkElement elem) :
            base(elem)
        {}

        public override void handleOnLoaded(object sender, EventArgs e)
        {
			Control control = sender as Control;
            Application.Current.RootVisual.KeyDown += BoardControl_KeyDown;
            HtmlPage.Plugin.Focus();
            control.Focus();
            iElement.Margin = new Thickness(extend/2, 0, 0, 0);
        }

        void BoardControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left || e.Key == Key.Right)
            {
                if (prevKeyVal == e.Key)
                    repeatMult += 5;
                else
                    repeatMult = 1;

                calculateDelta(((e.Key == Key.Left) ? -2 : 2) * repeatMult);
                prevKeyVal = e.Key;
            }
        }

        void BoardControl_KeyUp(object sender, KeyEventArgs e)
        {
            repeatMult = 1;
        }
    }
}

#endif